using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace tableColumnRename
{
    public partial class Form1 : Form
    {
        string originalsql = @" CREATE PROCEDURE [dbo].[Testprocedure_2]
                    @BusinessID NVARCHAR(100)
AS
BEGIN
SET NOCOUNT  ON;

SELECT dbo.tb_Rentals.*,
       SEA.MinimalRentalID,
       SEA.Name,
       SEA.BeginDay,
       SEA.EndDay,
       dbo.tb_RentalTypes.Name AS TypeName
FROM   dbo.tb_Rentals,
       dbo.tb_Seasons SEA,
       dbo.tb_RentalTypes,
       dbo.tb_RentalToSeason
WHERE  dbo.tb_Rentals.BusinessID_XXX = SEA.BusinessID 
       AND dbo.tb_Rentals.RentalTypeID = dbo.tb_RentalTypes.RentalTypeID
       AND dbo.tb_RentalToSeason.RentalID = dbo.tb_Rentals.RentalID
       AND dbo.tb_RentalToSeason.SeasonID = SEA.SeasonID
       AND dbo.tb_Rentals.BusinessID = @BusinessID 
       AND @BusinessID IN (SELECT DISTINCT dbo.tb_Rentals.BusinessID_XXX 
                           FROM   dbo.tb_Rentals
                           WHERE  dbo.tb_Rentals.BusinessID = @BusinessID)
END";
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.txtsql.Text = originalsql;
        }

        private void btntable_Click(object sender, EventArgs e)
        {
            renameObject ro = new renameObject(txtsql.Text);
            int ret = ro.renameTable(txtSourceTable.Text, txtTargetTable.Text);
            txtmsg.Text = ro.msg;
            if (ret > 0)
            {
                txtsql.Text = ro.getModifiedText();
            }
        }

        private void btnReload_Click(object sender, EventArgs e)
        {
            this.txtsql.Text = originalsql;
        }

        private void btncolumn_Click(object sender, EventArgs e)
        {
            renameObject ro = new renameObject(txtsql.Text);
            int ret = ro.renameColumn(txtSourceColumn.Text, txtTargetColumn.Text);
            txtmsg.Text = ro.msg;
            if (ret > 0)
            {
                txtsql.Text = ro.getModifiedText();
            }
        }


    }
}